﻿using DevExpress.XtraGrid.Demos.util;
using mendian;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DXApplicationTangche.UC.圣同润.merchant
{
    class MerchantService
    {
        public static List<HistoryOrder> getHistoryOrder(int brandId) {
            return
        FunctionHelper.JsonDeserialization<List<HistoryOrder>>(
            RestCall.httpGetMethod(
               XianglebaConnectDTO.接口url + "/order/getViewLogisticsBillEntryByBrandId?brandId=" + brandId 
            )
        );
        }

        /// <summary>
        /// 获取未发货订单一览
        /// </summary>
        /// <returns></returns>
        public static List<UnDeliveryOrderLogisticsInfo> getUnDeliveryOrderLogisticsInfo(int brandId)
        {
            return
                FunctionHelper.JsonDeserialization<List<UnDeliveryOrderLogisticsInfo>>(
                    RestCall.httpGetMethod(
                       XianglebaConnectDTO.接口url + "/order/getUnDeliveryOrderLogisticsInfoPage?brandId="+
                       brandId+
                       "&page=0&size=9999"
                    )
                );
        }

        /// <summary>
        /// 获取预订单一览
        /// </summary>
        /// <returns></returns>
        public static List<UnDeliveryOrderLogisticsInfo> getVirtualDeliveryOrderLogisticsInfoPage(int brandId)
        {
            return
                FunctionHelper.JsonDeserialization<List<UnDeliveryOrderLogisticsInfo>>(
                    RestCall.httpGetMethod(
                       XianglebaConnectDTO.接口url + "/order/getVirtualDeliveryOrderLogisticsInfoPage?brandId=" +
                       brandId +
                       "&page=0&size=9999"
                    )
                );
        }

        /// <summary>
        /// 获取预订单一览
        /// </summary>
        /// <returns></returns>
        public static List<UnDeliveryOrderLogisticsInfo> getExceptDeliveryOrderLogisticsInfoPage(int brandId)
        {
            return
                FunctionHelper.JsonDeserialization<List<UnDeliveryOrderLogisticsInfo>>(
                    RestCall.httpGetMethod(
                       XianglebaConnectDTO.接口url + "/order/getExceptDeliveryOrderLogisticsInfoPage?brandId=" + brandId 
                    )
                );
        }

        public static void saveLogisticsBodies(int brandId, String brandName,List<LogisticsBody> logisticsBodies) {
            String json = FunctionHelper.JsonSerialization(logisticsBodies);
            String rjson = RestCall.PostHttp(XianglebaConnectDTO.接口url + "/order/saveLogisticsBody?brandId="+ brandId + "&brandName="+ brandName, json);
        }


        public static void saveVirtualLogisticsBodies(int brandId, String brandName,String delivery_name,String delivery_id, List<String> logisticsNos)
        {
            String json = FunctionHelper.JsonSerialization(logisticsNos);
            String rjson = RestCall.PostHttp(
                XianglebaConnectDTO.接口url + "/order/generateLogisticsBatch?brandId=" + brandId 
                + "&brandName=" + brandName
                                + "&delivery_name=" + delivery_name
                                + "&delivery_id=" + delivery_id
                , json
                );
        }

        /// <summary>
        /// 获取未发货订单一览
        /// </summary>
        /// <returns></returns>
        public static String getBrandName(int brandId,String password)
        {
            return
                RestCall.httpGetMethod(
                       XianglebaConnectDTO.接口url + "/order/getBrandName?id=" + brandId+ "&password="+ password
                    );
        }
    }

    public class LogisticsBody { 
        public String delivery_id { get; set; }
        public String delivery_name { get; set; }
        public String order_sn { get; set; }

        public LogisticsBody(String delivery_id,String delivery_name,String order_sn) {
            this.delivery_id = delivery_id;
            this.delivery_name = delivery_name;
            this.order_sn = order_sn;
        }

        public LogisticsBody() { 
        
        }
    }

    public class UnDeliveryOrderLogisticsInfo {
        /// <summary>
        /// 
        /// </summary>
        public string order_sn { get; set; }
        /// <summary>
        /// 王索美
        /// </summary>
        public string real_name { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string user_phone { get; set; }
        /// <summary>
        /// 辽宁省 本溪市 溪湖区 彩北彩富路35号楼2单元5楼13号
        /// </summary>
        public string user_address { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int total_num { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public double total_price { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public double pay_price { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public double coupon_price { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public DateTime payTime { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public DateTime createTime { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string remark { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public DateTime logistics_order_time { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string product_id { get; set; }
        /// <summary>
        /// 泽米咕哒喵咛 辣白菜268g*10袋 共10袋共2680g 保质期6个月 0-4℃冷藏保存（72小时内发货）
        /// </summary>
        public string product_name { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public List<string> aftersale_status_desc { get; set; }
        /// <summary>
        /// 已支付
        /// </summary>
        public string pay_status_desc { get; set; }
        /// <summary>
        /// 未发货
        /// </summary>
        public string status_desc { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string refund_status_desc { get; set; }
        /// <summary>
        /// 慧采旗舰店
        /// </summary>
        public string mer_name { get; set; }
        /// <summary>
        /// 辽宁省
        /// </summary>
        public string province { get; set; }
        /// <summary>
        /// 本溪市
        /// </summary>
        public string city { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int paid { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int refundStatus { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int brandId { get; set; }
        /// <summary>
        /// 小佬幺（辽宁）食业有限公司
        /// </summary>
        public string brand_name { get; set; }
        /// <summary>
        /// 未发货
        /// </summary>
        public string order_status { get; set; }
        /// <summary>
        /// 未发货
        /// </summary>
        public string orderBaseStatus { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String virtualLogistics { get; set; }

        public String logistics_status { get; set; }
        public String delivery_name { get; set; }
        public String delivery_id { get; set; }
    }

    public class OrderLogisticsInfoImport
    {

        public OrderLogisticsInfoImport(DataRow dataRow)
        {
            this.order_sn = dataRow[0].ToString();
            this.real_name = dataRow[1].ToString();
            this.user_phone = dataRow[2].ToString();
            this.user_address = dataRow[3].ToString();
            try
            {
                this.total_num = int.Parse(dataRow[4].ToString());
            }
            catch (Exception ex)
            {
            }
            try
            {
                this.payTime = (DateTime)dataRow[5];
            }
            catch (Exception ex)
            {
            }
            this.product_name = dataRow[6].ToString();
            try
            {
                this.delivery_name = dataRow[7].ToString();
            }
            catch (Exception ex)
            {
            }
            try
            {
                this.delivery_id = dataRow[8].ToString();
            }
            catch (Exception ex)
            {
            }
        }

        public OrderLogisticsInfoImport(String order_sn,String real_name,String user_phone,String user_address,int total_num,DateTime payTime,String remark,String product_name,String orderBaseStatus)
        {
            this.order_sn = order_sn;
            this.real_name = real_name;
            this.user_phone = user_phone;
            this.user_address = user_address;
            this.total_num = total_num;
            this.payTime = payTime;
            this.remark = remark;
            this.product_name = product_name;
            this.orderBaseStatus = orderBaseStatus;
        }

        public LogisticsBody build() {
            return new LogisticsBody( this.delivery_id, this.delivery_name, this.order_sn);
        }

        /// <summary>
        /// 
        /// </summary>
        public string order_sn { get; set; }
        /// <summary>
        /// 王索美
        /// </summary>
        public string real_name { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string user_phone { get; set; }
        /// <summary>
        /// 辽宁省 本溪市 溪湖区 彩北彩富路35号楼2单元5楼13号
        /// </summary>
        public string user_address { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int total_num { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public DateTime payTime { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string remark { get; set; }
        /// <summary>
        /// 泽米咕哒喵咛 辣白菜268g*10袋 共10袋共2680g 保质期6个月 0-4℃冷藏保存（72小时内发货）
        /// </summary>
        public string product_name { get; set; }
        /// <summary>
        /// 未发货
        /// </summary>
        public string orderBaseStatus { get; set; }

        public String delivery_id { get; set; }
        public String delivery_name { get; set; }
    }

    public class HistoryOrder {
        /// <summary>
        /// 
        /// </summary>
        public string order_sn { get; set; }
        public DateTime createdate { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int brandId { get; set; }
        /// <summary>
        /// 小佬幺（辽宁）食业有限公司
        /// </summary>
        public string brandname { get; set; }
        /// <summary>
        /// 极兔速递
        /// </summary>
        public string delivery_name { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string delivery_id { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string virtuallogistics { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string logisticsbatchno { get; set; }
        /// <summary>
        /// 发货完成
        /// </summary>
        public string status { get; set; }
        /// <summary>
        /// "{\"status\":200,\"message\":\"订单物流信息修改成功\"}"
        /// </summary>
        public string message { get; set; }
        /// <summary>
        /// 王晓耘
        /// </summary>
        public string real_name { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string user_phone { get; set; }
        /// <summary>
        /// 辽宁省 大连市 沙河口区 西南路84号5-3
        /// </summary>
        public string user_address { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string total_num { get; set; }
        /// <summary>
        /// 倪膳坊 脱脂猪头肉1kg 送沈城一绝鸡架250g*1 保质期9个月 -18°C以下冷冻保存（72小时内发货）
        /// </summary>
        public string product_name { get; set; }
        /// <summary>
        /// 待收货
        /// </summary>
        public string order_status { get; set; }
    }
}
